<?php
/**
 * 拼团后台管理
 * hsx
 * 2022/7/16
 */
namespace App\Http\Controllers\web;

use App\Http\Controllers\Controller;
use App\Http\Requests\AddCollageGoodsPost;
use App\Repository\RepositoryInterface\GroupInterface;
use Illuminate\Http\Request;


//拼团类
class GroupController extends Controller
{
    //
    protected $group;


    public function __construct(GroupInterface $group){
        $this->group = $group;
    }

    /**
     * hsx
     * 拼团列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function groupList(Request $request){
        try {

            $size = $request->get('pageSize');

            $status = $request->get('status');

            return $this->group->groupList($size,$status);

        }catch (\Exception $exception){

            return parent::error($exception->getMessage());

        }
    }

    /**
     * hsx
     * 添加拼团
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addGroup(Request $request){
        try {

            $post = $request->post();

            return  $this->group->addGroup($post);

        }catch (\Exception $exception){

            return parent::error($exception->getMessage());

        }
    }

    /**
     * hsx
     * 拼团删除
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delGroup(Request $request){
        try {

            $id = $request->get('id');

            return $this->group->delGroup($id);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }

    /**
     * hsx
     * 拼团详情
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function groupDetails(Request $request){
        try {

            $id = $request->get('id');

            return  $this->group->groupDetails($id);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }

    /**
     * hsx
     * 拼团修改
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function groupAlter(Request $request)
    {
        try {
            $post = $request->post();

            return $this->group->groupAlter($post);

        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }
    }


    /**
     * hsx
     * 拼团商品列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function CollageGoodsList(Request $request)
    {
        try {

            $size = $request->get('pageSize');

            $is_show = $request->get('is_show');

            $title = $request->get('title');

            return $this->group->CollageGoodsList($size,$is_show,$title);

        } catch (\Exception $exception) {

            return parent::error($exception->getMessage());

        }
    }


    /**
     * hsx
     * 添加拼团商品
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addCollageGoods(AddCollageGoodsPost $request){
        try {

            $post = $request->validated();

            return  $this->group->addCollageGoods($post);


        } catch (\Exception $exception) {

            return parent::error($exception->getMessage());

        }
    }

    /**
     * hsx
     * 删除拼团商品
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delCollageGoods(Request $request){
        try {

            $id = $request->get('id');

            return  $this->group->delCollageGoods($id);

        } catch (\Exception $exception) {

            return parent::error($exception->getMessage());

        }
    }

    /**
     * hsx
     * 拼团商品详情
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function detailsCollageGoods(Request $request){
        try {

            $id = $request->get('id');

            return  $this->group->detailsCollageGoods($id);

        } catch (\Exception $exception) {

            return parent::error($exception->getMessage());

        }
    }

    /**
     * hsx
     * 修改拼团商品
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function updateCollageGoods(AddCollageGoodsPost $request){
        try {

            $post = $request->validated();

            return  $this->group->updateCollageGoods($post);

        } catch (\Exception $exception) {

            return parent::error($exception->getMessage());

        }
    }

    /**
     * hsx
     * 修改拼团商品状态
     * **
     */
    public function changeDiscountStatus(Request $request){
        try {

            $id = $request->get('id');

            $is_show = $request->get('is_show');

            return  $this->group->changeDiscountStatus($id,$is_show);

        } catch (\Exception $exception) {

            return parent::error($exception->getMessage());

        }
    }

    /**
     * 选择商品  hsx
     * @return \Illuminate\Http\JsonResponse
     */
    public function selectStoreProduct(){
        try {

            return  $this->group->selectStoreProduct();

        } catch (\Exception $exception) {

            return parent::error($exception->getMessage());

        }
    }


    /**
     * 拼团商品列表
     * @return mixed
     */
    public function combinationList(){
        return $this->group->combinationList();
    }
}
